import { getListApi, postListApi, postUpdateApi, getDeletApi } from '../../api/exam'

export default {
  namespaced: true,
  state: {
    examlist: [],
    pageSize: 10,
    currentPage: 1,
    sort: 'desc',
    orderby: 'id',
    total: 0
  },
  mutations: {
    SET_EXAM(state, examlist) {
      state.examlist = examlist
    },
    SET_CURRENT(state, currentPage) {
      state.currentPage = currentPage
    },
    SET_PAGESIZE(state, pageSize) {
      state.pageSize = pageSize
    },
    SET_TOTAL(state, total) {
      state.total = total
    }
  },
  actions: {
    async getExam({ commit, state }, searchValue) {
      let r = await getListApi({
        pageSize: state.pageSize,
        currentPage: state.currentPage - 1,
        sort: state.sort,
        orderby: state.orderby,
        searchValue: searchValue.ipt
      })
      console.log(r.data.data)
      commit('SET_EXAM', r.data)
      commit('SET_TOTAL', r.total[0].total)
    },
    async postExam({ commit }, form) {
      await postListApi(form)
    },
    async updateQuestions({ commit }, form) {
      await postUpdateApi({...form,options:form.option})
    },
    // async updateQuestions({commit},form){
    //   await updateQuestionsApi({...form,options:form.option})
    //   console.log(form)
    // },
    async delQuestions({ commit }, id) {
      await getDeletApi(id)
    }
  },
  getters: {

  }
}